﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="agendaProfessoresMaior2.aspx.cs" Inherits="sistemaAcademicoFinanceiroEscolas.agendaProfessorMaior2" %>

<%@ Register Src="~/DynamicData/Content/GridViewPager.ascx" TagName="GridViewPager"
    TagPrefix="asp" %>
<%@ Register Src="~/DynamicData/Content/FilterUserControl.ascx" TagName="DynamicFilter"
    TagPrefix="asp" %>
<%@ Register Assembly="Catalyst.Web.DynamicData" Namespace="Catalyst.Web.DynamicData"
    TagPrefix="asp" %>
<%--INSERIDAS ABAIXO AS REFERENCIAS PARA AJAX--%>
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="ajaxToolkit" %>

<script type="text/javascript" src="js/jquery.autocomplete.js"></script>



    
	

<head>
    <link rel="stylesheet" type="text/css" href="js/jquery.autocomplete.css" />
    <link rel="stylesheet" type="text/css" href="css/estilos.css" />
    <link href="Site.css" rel="stylesheet" type="text/css" />
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <meta charset="utf-8">
    <link rel="stylesheet" href="js/jquery-ui.css">

    <script src="js/jquery-1.8.3.js"></script>

    <script src="js/jquery-ui.js"></script>

    <link rel="stylesheet" href="js/style.css">

    <script src="js/jquery.min.js" type="text/javascript"></script>

    <script src="js/jquery-ui.min.js" type="text/javascript"></script>

    <link rel="stylesheet" type="text/css" href="css/jquery-ui.css" />
    


    
    
    <%
        System.Data.SqlClient.SqlConnection sqlj = new System.Data.SqlClient.SqlConnection(ConfigurationManager.AppSettings["baseDados"]);
        sqlj.Open();

        string dia = lstDia.SelectedItem.Text;
        string ano = lstAnoLetivo.SelectedItem.Text;
        string mes = lstMes.SelectedValue;
        if (dia.Length == 1)
        {
            dia = "0" + dia;
        }
        if (mes.Length == 1)
        {
            mes = "0" + mes;
        }

        string selectAula = "SELECT codigoAula, codigoProfessor, codigoAluno, codigoGrupo, dataAula, horaInicialAula, ";
        selectAula += "horaFinalAula, codigoDisciplina, descricaoAssuntoAula, observacoesAula, ";
        selectAula += "aulaRealizada, valorHora, valorTotalSemDesconto, valorTotalComDesconto, falta, codigoAnoLetivo, linha, ";

        selectAula += "(SELECT MIN(horaInicialAula) AS horaInicial FROM aula AS a WHERE (linha = '1') AND (codigoProfessor = " + lstProfessor.SelectedValue + ") AND (dataAula = '" + dia + "/" + mes + "/" + ano + "')) AS horaInicial, ";
        selectAula += "(SELECT MAX(horaFinalAula) AS horaFinal FROM aula AS aa WHERE (linha = '1') AND (codigoProfessor = " + lstProfessor.SelectedValue + ") AND (dataAula = '" + dia + "/" + mes + "/" + ano + "')) AS horaFinal, ";
        selectAula += "(SELECT MIN(horaInicialAula) AS horaInicial2 FROM aula AS a WHERE (linha = '2') AND (codigoProfessor = " + lstProfessor.SelectedValue + ") AND (dataAula = '" + dia + "/" + mes + "/" + ano + "')) AS horaInicial2, ";
        selectAula += "(SELECT MAX(horaFinalAula) AS horaFinal2 FROM aula AS aa WHERE (linha = '2') AND (codigoProfessor = " + lstProfessor.SelectedValue + ") AND (dataAula = '" + dia + "/" + mes + "/" + ano + "')) AS horaFinal2, ";
        selectAula += "(SELECT MIN(horaInicialAula) AS horaInicial3 FROM aula AS a WHERE (linha = '3') AND (codigoProfessor = " + lstProfessor.SelectedValue + ") AND (dataAula = '" + dia + "/" + mes + "/" + ano + "')) AS horaInicial3, ";
        selectAula += "(SELECT MAX(horaFinalAula) AS horaFinal3 FROM aula AS aa WHERE (linha = '3') AND (codigoProfessor = " + lstProfessor.SelectedValue + ") AND (dataAula = '" + dia + "/" + mes + "/" + ano + "')) AS horaFinal3, ";
        selectAula += "(SELECT MIN(horaInicialAula) AS horaInicial4 FROM aula AS a WHERE (linha = '4') AND (codigoProfessor = " + lstProfessor.SelectedValue + ") AND (dataAula = '" + dia + "/" + mes + "/" + ano + "')) AS horaInicial4, ";
        selectAula += "(SELECT MAX(horaFinalAula) AS horaFinal4 FROM aula AS aa WHERE (linha = '4') AND (codigoProfessor = " + lstProfessor.SelectedValue + ") AND (dataAula = '" + dia + "/" + mes + "/" + ano + "')) AS horaFinal4, ";
        selectAula += "(SELECT MIN(horaInicialAula) AS horaInicial5 FROM aula AS a WHERE (linha = '5') AND (codigoProfessor = " + lstProfessor.SelectedValue + ") AND (dataAula = '" + dia + "/" + mes + "/" + ano + "')) AS horaInicial5, ";
        selectAula += "(SELECT MAX(horaFinalAula) AS horaFinal5 FROM aula AS aa WHERE (linha = '5') AND (codigoProfessor = " + lstProfessor.SelectedValue + ") AND (dataAula = '" + dia + "/" + mes + "/" + ano + "')) AS horaFinal5, ";
        selectAula += "(SELECT MIN(horaInicialAula) AS horaInicial6 FROM aula AS a WHERE (linha = '6') AND (codigoProfessor = " + lstProfessor.SelectedValue + ") AND (dataAula = '" + dia + "/" + mes + "/" + ano + "')) AS horaInicial6, ";
        selectAula += "(SELECT MAX(horaFinalAula) AS horaFinal6 FROM aula AS aa WHERE (linha = '6') AND (codigoProfessor = " + lstProfessor.SelectedValue + ") AND (dataAula = '" + dia + "/" + mes + "/" + ano + "')) AS horaFinal6, ";
        selectAula += "(SELECT MIN(horaInicialAula) AS horaInicial7 FROM aula AS a WHERE (linha = '7') AND (codigoProfessor = " + lstProfessor.SelectedValue + ") AND (dataAula = '" + dia + "/" + mes + "/" + ano + "')) AS horaInicial7, ";
        selectAula += "(SELECT MAX(horaFinalAula) AS horaFinal7 FROM aula AS aa WHERE (linha = '7') AND (codigoProfessor = " + lstProfessor.SelectedValue + ") AND (dataAula = '" + dia + "/" + mes + "/" + ano + "')) AS horaFinal7, ";
        selectAula += "(SELECT MIN(horaInicialAula) AS horaInicial8 FROM aula AS a WHERE (linha = '8') AND (codigoProfessor = " + lstProfessor.SelectedValue + ") AND (dataAula = '" + dia + "/" + mes + "/" + ano + "')) AS horaInicial8, ";
        selectAula += "(SELECT MAX(horaFinalAula) AS horaFinal8 FROM aula AS aa WHERE (linha = '8') AND (codigoProfessor = " + lstProfessor.SelectedValue + ") AND (dataAula = '" + dia + "/" + mes + "/" + ano + "')) AS horaFinal8 ";

        selectAula += "FROM aula WHERE (codigoProfessor = " + lstProfessor.SelectedValue + ") AND (dataAula = '" + dia + "/" + mes + "/" + ano + "')";


        System.Data.SqlClient.SqlCommand cmdselectAula = new System.Data.SqlClient.SqlCommand(selectAula, sqlj);
        System.Data.SqlClient.SqlDataReader drselectAula = cmdselectAula.ExecuteReader();



        string hora1Inicial = "";
        string hora1Final = "";

        string hora2Inicial = "";
        string hora2Final = "";

        string hora3Inicial = "";
        string hora3Final = "";

        string hora4Inicial = "";
        string hora4Final = "";

        string hora5Inicial = "";
        string hora5Final = "";

        string hora6Inicial = "";
        string hora6Final = "";

        string hora7Inicial = "";
        string hora7Final = "";

        string hora8Inicial = "";
        string hora8Final = "";

        Session["hora1Inicial"] = "";
        Session["hora1Final"] = "";
        Session["hora2Inicial"] = "";
        Session["hora2Final"] = "";
        Session["hora3Inicial"] = "";
        Session["hora3Final"] = "";
        Session["hora4Inicial"] = "";
        Session["hora4Final"] = "";
        Session["hora5Inicial"] = "";
        Session["hora5Final"] = "";
        Session["hora6Inicial"] = "";
        Session["hora6Final"] = "";
        Session["hora7Inicial"] = "";
        Session["hora7Final"] = "";
        Session["hora8Inicial"] = "";
        Session["hora8Final"] = "";

        if (drselectAula.HasRows)
        {
            while (drselectAula.Read())
            {
                hora1Inicial = drselectAula["horaInicial"].ToString();
                hora1Final = drselectAula["horaFinal"].ToString();

                hora2Inicial = drselectAula["horaInicial2"].ToString();
                hora2Final = drselectAula["horaFinal2"].ToString();

                hora3Inicial = drselectAula["horaInicial3"].ToString();
                hora3Final = drselectAula["horaFinal3"].ToString();

                hora4Inicial = drselectAula["horaInicial4"].ToString();
                hora4Final = drselectAula["horaFinal4"].ToString();

                hora5Inicial = drselectAula["horaInicial5"].ToString();
                hora5Final = drselectAula["horaFinal5"].ToString();

                hora6Inicial = drselectAula["horaInicial6"].ToString();
                hora6Final = drselectAula["horaFinal6"].ToString();

                hora7Inicial = drselectAula["horaInicial7"].ToString();
                hora7Final = drselectAula["horaFinal7"].ToString();

                hora8Inicial = drselectAula["horaInicial8"].ToString();
                hora8Final = drselectAula["horaFinal8"].ToString();

                switch (drselectAula["linha"].ToString())
                {
                    case "1":
                        if (hora1Inicial != "" && hora1Final != "")
                        {
                            Session["hora1Inicial"] = drselectAula["horaInicial"].ToString();
                            Session["hora1Final"] = drselectAula["horaFinal"].ToString();
                        }
                        break;
                    case "2":
                        if (hora2Inicial != "" && hora2Final != "")
                        {
                            Session["hora2Inicial"] = drselectAula["horaInicial2"].ToString();
                            Session["hora2Final"] = drselectAula["horaFinal2"].ToString();
                        }
                        break;
                    case "3":
                        if (hora3Inicial != "" && hora3Final != "")
                        {
                            Session["hora3Inicial"] = drselectAula["horaInicial3"].ToString();
                            Session["hora3Final"] = drselectAula["horaFinal3"].ToString();
                        }
                        break;
                    case "4":
                        if (hora4Inicial != "" && hora4Final != "")
                        {
                            Session["hora4Inicial"] = drselectAula["horaInicial4"].ToString();
                            Session["hora4Final"] = drselectAula["horaFinal4"].ToString();
                        }
                        break;
                    case "5":
                        if (hora5Inicial != "" && hora5Final != "")
                        {
                            Session["hora5Inicial"] = drselectAula["horaInicial5"].ToString();
                            Session["hora5Final"] = drselectAula["horaFinal5"].ToString();
                        }
                        break;
                    case "6":
                        if (hora6Inicial != "" && hora6Final != "")
                        {
                            Session["hora6Inicial"] = drselectAula["horaInicial6"].ToString();
                            Session["hora6Final"] = drselectAula["horaFinal6"].ToString();
                        }
                        break;
                    case "7":
                        if (hora7Inicial != "" && hora7Final != "")
                        {
                            Session["hora7Inicial"] = drselectAula["horaInicial7"].ToString();
                            Session["hora7Final"] = drselectAula["horaFinal7"].ToString();
                        }
                        break;
                    default:
                        if (hora8Inicial != "" && hora8Final != "")
                        {
                            Session["hora8Inicial"] = drselectAula["horaInicial8"].ToString();
                            Session["hora8Final"] = drselectAula["horaFinal8"].ToString();
                        }
                        break;
                }
            }
        }

        drselectAula.Close();

        sqlj.Close();

        
    %>

    <%--<script>

    $(function() {
        
        $("#slider-range11").slider({
                range: true,
                min: 300,
                max: 1389,
                values: [<%=hora1Inicial %> * 60, <%=hora1Final %> * 60],
                slide: slideTime
            });
            function slideTime(event, ui) {
                var val0 = $("#slider-range11").slider("values", 0),
					val1 = $("#slider-range11").slider("values", 1),
					minutes0 = parseInt(val0 % 60, 10),
					hours0 = parseInt(val0 / 60 % 24, 10),
					minutes1 = parseInt(val1 % 60, 10),
					hours1 = parseInt(val1 / 60 % 24, 10);

                if (minutes0 > 15) {
                    minutes0 = 30;
                } else {
                    minutes0 = 0;
                }
                if (minutes1 > 15) {
                    minutes1 = 30;
                } else {
                minutes1 = 0;
                }

                startTime = getTime(hours0, minutes0);
                endTime = getTime(hours1, minutes1);


                var objHid11 = document.getElementById("hora1");
                objHid11.value = startTime;

                var objHid211 = document.getElementById("hora12");
                objHid211.value = endTime;
                
                
                $("#Text11").text(startTime + ' às ' + endTime);
            }
            function getTime(hours, minutes) {
                minutes = minutes + "";
                if (hours == 0) {
                    hours = 12;
                }
                if (minutes.length == 1) {
                    minutes = "0" + minutes;
                }
                return hours + ":" + minutes;
            }
            slideTime();
        
        $("#Div1").slider({
                range: true,
                min: 300,
                max: 1389,
                values: [<%=hora2Inicial %> * 60, <%=hora2Final %> * 60],
                slide: slideTime2
            });
            function slideTime2(event, ui) {
                var val0 = $("#Div1").slider("values", 0),
					val1 = $("#Div1").slider("values", 1),
					minutes0 = parseInt(val0 % 60, 10),
					hours0 = parseInt(val0 / 60 % 24, 10),
					minutes1 = parseInt(val1 % 60, 10),
					hours1 = parseInt(val1 / 60 % 24, 10);

                if (minutes0 > 15) {
                    minutes0 = 30;
                } else {
                    minutes0 = 0;
                }
                if (minutes1 > 15) {
                    minutes1 = 30;
                } else {
                minutes1 = 0;
                }

                startTime = getTime2(hours0, minutes0);
                endTime = getTime2(hours1, minutes1);


                var objHid11 = document.getElementById("hora2");
                objHid11.value = startTime;

                var objHid211 = document.getElementById("hora22");
                objHid211.value = endTime;
                
                
                $("#Text3").text(startTime + ' às ' + endTime);
            }
            function getTime2(hours, minutes) {
                minutes = minutes + "";
                if (hours == 0) {
                    hours = 12;
                }
                if (minutes.length == 1) {
                    minutes = "0" + minutes;
                }
                return hours + ":" + minutes;
            }
            slideTime2();

        $("#Div2").slider({
                range: true,
                min: 300,
                max: 1389,
                values: [<%=hora3Inicial %> * 60, <%=hora3Final %> * 60],
                slide: slideTime3
            });
            function slideTime3(event, ui) {
                var val0 = $("#Div2").slider("values", 0),
					val1 = $("#Div2").slider("values", 1),
					minutes0 = parseInt(val0 % 60, 10),
					hours0 = parseInt(val0 / 60 % 24, 10),
					minutes1 = parseInt(val1 % 60, 10),
					hours1 = parseInt(val1 / 60 % 24, 10);

                if (minutes0 > 15) {
                    minutes0 = 30;
                } else {
                    minutes0 = 0;
                }
                if (minutes1 > 15) {
                    minutes1 = 30;
                } else {
                minutes1 = 0;
                }

                startTime = getTime3(hours0, minutes0);
                endTime = getTime3(hours1, minutes1);


                var objHid11 = document.getElementById("hora3");
                objHid11.value = startTime;

                var objHid211 = document.getElementById("hora32");
                objHid211.value = endTime;
                
                
                $("#Text6").text(startTime + ' às ' + endTime);
            }
            function getTime3(hours, minutes) {
                minutes = minutes + "";
                if (hours == 0) {
                    hours = 12;
                }
                if (minutes.length == 1) {
                    minutes = "0" + minutes;
                }
                return hours + ":" + minutes;
            }
            slideTime3();

        $("#Div3").slider({
                range: true,
                min: 300,
                max: 1389,
                values: [<%=hora4Inicial %> * 60, <%=hora4Final %> * 60],
                slide: slideTime4
            });
            function slideTime4(event, ui) {
                var val0 = $("#Div3").slider("values", 0),
					val1 = $("#Div3").slider("values", 1),
					minutes0 = parseInt(val0 % 60, 10),
					hours0 = parseInt(val0 / 60 % 24, 10),
					minutes1 = parseInt(val1 % 60, 10),
					hours1 = parseInt(val1 / 60 % 24, 10);

                if (minutes0 > 15) {
                    minutes0 = 30;
                } else {
                    minutes0 = 0;
                }
                if (minutes1 > 15) {
                    minutes1 = 30;
                } else {
                minutes1 = 0;
                }

                startTime = getTime4(hours0, minutes0);
                endTime = getTime4(hours1, minutes1);


                var objHid11 = document.getElementById("hora4");
                objHid11.value = startTime;

                var objHid211 = document.getElementById("hora42");
                objHid211.value = endTime;
                
                
                $("#Text9").text(startTime + ' às ' + endTime);
            }
            function getTime4(hours, minutes) {
                minutes = minutes + "";
                if (hours == 0) {
                    hours = 12;
                }
                if (minutes.length == 1) {
                    minutes = "0" + minutes;
                }
                return hours + ":" + minutes;
            }
            slideTime4();

        $("#Div4").slider({
                range: true,
                min: 300,
                max: 1389,
                values: [<%=hora5Inicial %> * 60, <%=hora5Final %> * 60],
                slide: slideTime5
            });
            function slideTime5(event, ui) {
                var val0 = $("#Div4").slider("values", 0),
					val1 = $("#Div4").slider("values", 1),
					minutes0 = parseInt(val0 % 60, 10),
					hours0 = parseInt(val0 / 60 % 24, 10),
					minutes1 = parseInt(val1 % 60, 10),
					hours1 = parseInt(val1 / 60 % 24, 10);

                if (minutes0 > 15) {
                    minutes0 = 30;
                } else {
                    minutes0 = 0;
                }
                if (minutes1 > 15) {
                    minutes1 = 30;
                } else {
                minutes1 = 0;
                }

                startTime = getTime5(hours0, minutes0);
                endTime = getTime5(hours1, minutes1);


                var objHid11 = document.getElementById("hora5");
                objHid11.value = startTime;

                var objHid211 = document.getElementById("hora52");
                objHid211.value = endTime;
                
                
                $("#Text12").text(startTime + ' às ' + endTime);
            }
            function getTime5(hours, minutes) {
                minutes = minutes + "";
                if (hours == 0) {
                    hours = 12;
                }
                if (minutes.length == 1) {
                    minutes = "0" + minutes;
                }
                return hours + ":" + minutes;
            }
            slideTime5();

        $("#Div5").slider({
                range: true,
                min: 300,
                max: 1389,
                values: [<%=hora6Inicial %> * 60, <%=hora6Final %> * 60],
                slide: slideTime6
            });
            function slideTime6(event, ui) {
                var val0 = $("#Div5").slider("values", 0),
					val1 = $("#Div5").slider("values", 1),
					minutes0 = parseInt(val0 % 60, 10),
					hours0 = parseInt(val0 / 60 % 24, 10),
					minutes1 = parseInt(val1 % 60, 10),
					hours1 = parseInt(val1 / 60 % 24, 10);

                if (minutes0 > 15) {
                    minutes0 = 30;
                } else {
                    minutes0 = 0;
                }
                if (minutes1 > 15) {
                    minutes1 = 30;
                } else {
                minutes1 = 0;
                }

                startTime = getTime6(hours0, minutes0);
                endTime = getTime6(hours1, minutes1);


                var objHid11 = document.getElementById("hora6");
                objHid11.value = startTime;

                var objHid211 = document.getElementById("hora62");
                objHid211.value = endTime;
                
                
                $("#Text13").text(startTime + ' às ' + endTime);
            }
            function getTime6(hours, minutes) {
                minutes = minutes + "";
                if (hours == 0) {
                    hours = 12;
                }
                if (minutes.length == 1) {
                    minutes = "0" + minutes;
                }
                return hours + ":" + minutes;
            }
            slideTime6();

        $("#Div6").slider({
                range: true,
                min: 300,
                max: 1389,
                values: [<%=hora7Inicial %> * 60, <%=hora7Final %> * 60],
                slide: slideTime7
            });
            function slideTime7(event, ui) {
                var val0 = $("#Div6").slider("values", 0),
					val1 = $("#Div6").slider("values", 1),
					minutes0 = parseInt(val0 % 60, 10),
					hours0 = parseInt(val0 / 60 % 24, 10),
					minutes1 = parseInt(val1 % 60, 10),
					hours1 = parseInt(val1 / 60 % 24, 10);

                if (minutes0 > 15) {
                    minutes0 = 30;
                } else {
                    minutes0 = 0;
                }
                if (minutes1 > 15) {
                    minutes1 = 30;
                } else {
                minutes1 = 0;
                }

                startTime = getTime7(hours0, minutes0);
                endTime = getTime7(hours1, minutes1);


                var objHid11 = document.getElementById("hora7");
                objHid11.value = startTime;

                var objHid211 = document.getElementById("hora72");
                objHid211.value = endTime;
                
                
                $("#Text14").text(startTime + ' às ' + endTime);
            }
            function getTime7(hours, minutes) {
                minutes = minutes + "";
                if (hours == 0) {
                    hours = 12;
                }
                if (minutes.length == 1) {
                    minutes = "0" + minutes;
                }
                return hours + ":" + minutes;
            }
            slideTime7();

        $("#Div7").slider({
                range: true,
                min: 300,
                max: 1389,
                values: [<%=hora8Inicial %> * 60, <%=hora8Final %> * 60],
                slide: slideTime8
            });
            function slideTime8(event, ui) {
                var val0 = $("#Div7").slider("values", 0),
					val1 = $("#Div7").slider("values", 1),
					minutes0 = parseInt(val0 % 60, 10),
					hours0 = parseInt(val0 / 60 % 24, 10),
					minutes1 = parseInt(val1 % 60, 10),
					hours1 = parseInt(val1 / 60 % 24, 10);

                if (minutes0 > 15) {
                    minutes0 = 30;
                } else {
                    minutes0 = 0;
                }
                if (minutes1 > 15) {
                    minutes1 = 30;
                } else {
                minutes1 = 0;
                }

                startTime = getTime8(hours0, minutes0);
                endTime = getTime8(hours1, minutes1);


                var objHid11 = document.getElementById("hora7");
                objHid11.value = startTime;

                var objHid211 = document.getElementById("hora72");
                objHid211.value = endTime;
                
                
                $("#Text15").text(startTime + ' às ' + endTime);
            }
            function getTime8(hours, minutes) {
                minutes = minutes + "";
                if (hours == 0) {
                    hours = 12;
                }
                if (minutes.length == 1) {
                    minutes = "0" + minutes;
                }
                return hours + ":" + minutes;
            }
            slideTime8();
    });
    </script>--%>

    <script language="javascript">

        function horasIguais1() {
            alert('Deve existir um espaço mínimo de uma hora para cada aula. (Linha 1)');
        }
        function existe1() {
            alert('Já existe uma aula definida para esse professor dentro deste intervalo de tempo. (Linha 1)');
        }
        function alunoGrupo1() {
            alert('Selecione apenas uma opção aluno ou grupo. (Linha 1)');
        }

        function horasIguais2() {
            alert('Deve existir um espaço mínimo de uma hora para cada aula. (Linha 2)');
        }
        function existe2() {
            alert('Já existe uma aula definida para esse professor dentro deste intervalo de tempo. (Linha 2)');
        }
        function alunoGrupo2() {
            alert('Selecione apenas uma opção aluno ou grupo. (Linha 2)');
        }

        function horasIguais3() {
            alert('Deve existir um espaço mínimo de uma hora para cada aula. (Linha 3)');
        }
        function existe3() {
            alert('Já existe uma aula definida para esse professor dentro deste intervalo de tempo. (Linha 3)');
        }
        function alunoGrupo3() {
            alert('Selecione apenas uma opção aluno ou grupo. (Linha 3)');
        }

        function horasIguais4() {
            alert('Deve existir um espaço mínimo de uma hora para cada aula. (Linha 4)');
        }
        function existe4() {
            alert('Já existe uma aula definida para esse professor dentro deste intervalo de tempo. (Linha 4)');
        }
        function alunoGrupo4() {
            alert('Selecione apenas uma opção aluno ou grupo. (Linha 4)');
        }

        function horasIguais5() {
            alert('Deve existir um espaço mínimo de uma hora para cada aula. (Linha 5)');
        }
        function existe5() {
            alert('Já existe uma aula definida para esse professor dentro deste intervalo de tempo. (Linha 5)');
        }
        function alunoGrupo5() {
            alert('Selecione apenas uma opção aluno ou grupo. (Linha 5)');
        }

        function horasIguais6() {
            alert('Deve existir um espaço mínimo de uma hora para cada aula. (Linha 6)');
        }
        function existe6() {
            alert('Já existe uma aula definida para esse professor dentro deste intervalo de tempo. (Linha 6)');
        }
        function alunoGrupo6() {
            alert('Selecione apenas uma opção aluno ou grupo. (Linha 6)');
        }

        function horasIguais7() {
            alert('Deve existir um espaço mínimo de uma hora para cada aula. (Linha 7)');
        }
        function existe7() {
            alert('Já existe uma aula definida para esse professor dentro deste intervalo de tempo. (Linha 7)');
        }
        function alunoGrupo7() {
            alert('Selecione apenas uma opção aluno ou grupo. (Linha 7)');
        }

        function horasIguais8() {
            alert('Deve existir um espaço mínimo de uma hora para cada aula. (Linha 8)');
        }
        function existe8() {
            alert('Já existe uma aula definida para esse professor dentro deste intervalo de tempo. (Linha 8)');
        }
        function alunoGrupo8() {
            alert('Selecione apenas uma opção aluno ou grupo. (Linha 8)');
        }

        function finalizar1() {
            //alert('Registro salvo com sucesso. (Linha 1)');
            alert('Registros salvos com sucesso.');
        }

        function finalizar2() {
            //alert('Registro salvo com sucesso. (Linha 2)');
        }

        function finalizar3() {
            //alert('Registro salvo com sucesso. (Linha 3)');
        }

        function finalizar4() {
            //alert('Registro salvo com sucesso. (Linha 4)');
        }

        function finalizar5() {
            //alert('Registro salvo com sucesso. (Linha 5)');
        }
    </script>

<script language="javascript">

    function formatar(src, mask) {

        var i = src.value.length;
        var saida = mask.substring(0, 1);
        var texto = mask.substring(i);
        var hora = src.value.substring(0, 2);
        var min = src.value.substring(3, 5);

        if (texto.substring(0, 1) != saida) {
            src.value += texto.substring(0, 1);
        }
        if (i == 5) {
            verifica_hora(hora, min);
        }
        var charCode = (src.which) ? src.which : event.keyCode
        if (charCode > 31 && (charCode < 48 || charCode > 57))
            return false;
        return true;
    }


//    function mascara_hora(hora) {
//        var myhora = '';
//        myhora = myhora + hora;
//        if (myhora.length == 2) {
//            myhora = myhora + ':';
//            document.forms[0].hora.value = myhora;
//        }
//        if (myhora.length == 5) {
//            verifica_hora();
//        }
//    }

    function verifica_hora(hrs, min) {

        //alert('hrs '+ hrs); 
        //alert('min '+ min); 

        situacao = "";
        // verifica data e hora 
        if ((hrs < 00) || (hrs > 23) || (min < 00) || (min > 59)) {
            situacao = "falsa";
        }

        if (situacao == "falsa") {
            alert("Hora invalida. Informe a hora entre 00:00 e 23:00");
            document.forms[0].hora.focus();
        }
    } 
    </script>

    <style type="text/css">
        .style1
        {
            font-family: Verdana, Arial, Helvetica, sans-serif;
            font-size: 12px;
            color: #CCFFFF;
            width: 177px;
        }
        .style2
        {
            width: 177px;
        }
        .style3
        {
            font-family: Verdana, Arial, Helvetica, sans-serif;
            font-size: 300px;
            font-weight: bold;
            color: Blue;
            height: 500px;
        }
        .style4
        {
            height: 500px;
        }
        .style5
        {
            width: 177px;
            height: 74px;
        }
        .style6
        {
            height: 74px;
        }
    </style>
</head>
<form id="form1" runat="server">
<table width="100%" border="0">
    <tr>
        <td class="titulo">
            Agenda de aulas dos professores
        </td>
    </tr>
    <tr>
        <td>
            &nbsp;
        </td>
    </tr>
    <tr>
        <td>
            <table border="0">
                <tr>
                    <td class="textoNegro">
                        Professor
                    </td>
                    <td>
                        <asp:dropdownlist id="lstProfessor" runat="server">
                            </asp:dropdownlist>
                    </td>
                    <td class="textoNegro">
                        Ano Letivo
                    </td>
                    <td>
                        <asp:dropdownlist id="lstAnoLetivo" runat="server">
                            </asp:dropdownlist>
                    </td>
                    <td class="textoNegro">
                        Mês
                    </td>
                    <td>
                        <asp:dropdownlist id="lstMes" runat="server" onselectedindexchanged="lstMes_SelectedIndexChanged"
                            autopostback="True">
                            </asp:dropdownlist>
                    </td>
                    <td class="textoNegro">
                        Dia
                    </td>
                    <td>
                        <asp:dropdownlist id="lstDia" runat="server">
                            </asp:dropdownlist>
                    </td>
                    <td align="right">
                        <asp:button id="btnVerificar" runat="server" text="Listar Horários" onclick="btnVerificar_Click" />
                        <%--Botão salvar--%>
                        <asp:button id="BtnSalvar" runat="server" text="Salvar" onclick="btnSalvar_Click"
                            visible="False" />
                    </td>
                    <td>
                        &nbsp;
                    </td>
                </tr>
                <tr>
                    <td class="textovermelho" colspan="10">
                        <asp:label runat="server" text="" id="lblValidacao"></asp:label>
                    </td>
                </tr>
            </table>
        </td>
    </tr>
</table>

<script type="text/javascript" src="js/jquery.autocomplete.js"></script>

<link rel="stylesheet" type="text/css" href="js/jquery.autocomplete.css" />
<link rel="stylesheet" type="text/css" href="css/estilos.css" />
<link href="Site.css" rel="stylesheet" type="text/css" />
<%--FORM ALUNO COM A CLASS PARA SER MODIFICADO NO code behind .cs--%>
<asp:panel id="Panel1" runat="server" visible="False">

    <table width="100%" border="1" cellpadding="5" cellspacing="0" bordercolor="#0000FF">
        <tr>
            <th width="20%" class="textoNegro" align=center style="font-size:12px; color: #0000FF; font-weight: bold;">
                <strong>DIA</strong>
            </th>
            <th width="80%" cellpadding="10" class="textoNegro" align=center style="font-size:12px; color: #0000FF; font-weight: bold;">
                <strong>DISPONIBILIDADE</strong>
            </th>
        </tr>
        <tr>
            <td width="20%" align="center" valign="middle" class="style3">
                <strong><%=lstDia.SelectedItem.Text %></strong>
            </td>
            <td class="style4" align=center valign=top><table width=100% style="height: 500px"><tr style="background-color:#CCFFFF" align="center" valign="middle">
            <td class="style1">
            
            <table><tr><td>Hora inicial: 
                            <asp:TextBox ID="inicial1Hora1" runat="server" OnKeyUp="return(formatar(this, '##:##'));" maxlength="5" ></asp:TextBox></td><td>Hora final: 
                            <asp:TextBox ID="final1Hora1" runat="server" OnKeyUp="return(formatar(this, '##:##'));" maxlength="5" ></asp:TextBox></td></tr></table> 
                            
                            
                            
                        </td>
                        <td>
                            Disciplina
                        <asp:dropdownlist id="lstmateria" runat="server">
                            </asp:dropdownlist>
                        </td>
                        <td>
                            Aluno
                            <asp:TextBox runat="server" id="txt1" class="aluno" ></asp:TextBox>
                            <asp:HiddenField id="hide1" runat="server" value="0"></asp:HiddenField>
                        </td>
                        <td>
                            Grupo
                        <asp:dropdownlist id="lstgrupo" runat="server">
                            </asp:dropdownlist>
                        </td>
                        <!--<td>
                            Valor
                            <asp:TextBox id="txtValor1" runat="server"></asp:TextBox>
                        </td>
                        -->
                    </tr>
                    <tr  style="background-color:#f6f9fc" align="center" valign="middle">
                        <td class="style2">
                         <table><tr><td>Hora inicial: 
                            <asp:TextBox ID="inicial2Hora2" runat="server" maxlength="5" OnKeyUp="return(formatar(this, '##:##'));"></asp:TextBox></td><td>Hora final: 
                            <asp:TextBox ID="final2Hora2" runat="server" maxlength="5" OnKeyUp="return(formatar(this, '##:##'));"></asp:TextBox></td></tr></table> 
                        </td>
                        <td>
                            Disciplina
                        <asp:dropdownlist id="lstmateria2" runat="server">
                            </asp:dropdownlist>
                        </td>
                        <td>
                            Aluno
                            <asp:TextBox runat="server" id="txt2" class="aluno" ></asp:TextBox><asp:HiddenField id="hide2" runat="server" value="0"></asp:HiddenField>
                        
                        </td>
                        <td>
                            Grupo
                        <asp:dropdownlist id="lstgrupo2" runat="server">
                            </asp:dropdownlist>
                        </td>
                        <!--
                        <td>
                            Valor
                            <asp:TextBox id="txtValor2" runat="server"></asp:TextBox>
                        </td>
                        -->
                    </tr>
                    <tr style="background-color:#CCFFFF" align="center" valign="middle">
                        <td class="style2">
               <table><tr><td>Hora inicial: 
                            <asp:TextBox ID="inicial3Hora3" runat="server" maxlength="5" OnKeyUp="return(formatar(this, '##:##'));"></asp:TextBox></td><td>Hora final: 
                            <asp:TextBox ID="final3Hora3" runat="server" maxlength="5" OnKeyUp="return(formatar(this, '##:##'));"></asp:TextBox></td></tr></table> 
                            
                        </td>
                        <td>
                            Disciplina
                        <asp:dropdownlist id="lstmateria3" runat="server">
                            </asp:dropdownlist>
                        </td>
                        <td>
                            Aluno
                            <asp:TextBox runat="server" id="txt3" class="aluno" ></asp:TextBox><asp:HiddenField id="hide3" runat="server" value="0"></asp:HiddenField>
                        
                        </td>
                        <td>
                            Grupo
                        <asp:dropdownlist id="lstgrupo3" runat="server">
                            </asp:dropdownlist>
                        </td>
                        <!--
                        <td>
                            Valor
                            <asp:TextBox id="txtValor3" runat="server"></asp:TextBox>
                        </td>
                        -->
                    </tr>
                    <tr style="background-color:#f6f9fc" align="center" valign="middle">
                        <td class="style2">
                           <table><tr><td>Hora inicial: 
                            <asp:TextBox ID="inicial4Hora4" runat="server" maxlength="5" OnKeyUp="return(formatar(this, '##:##'));"></asp:TextBox></td><td>Hora final: 
                            <asp:TextBox ID="final4Hora4" runat="server" maxlength="5" OnKeyUp="return(formatar(this, '##:##'));"></asp:TextBox></td></tr></table> 
                            
                        </td>
                        <td>
                            Disciplina
                        <asp:dropdownlist id="lstmateria4" runat="server">
                            </asp:dropdownlist>
                        </td>
                        <td>
                            Aluno
                            <asp:TextBox runat="server" id="txt4" class="aluno" ></asp:TextBox><asp:HiddenField id="hide4" runat="server" value="0"></asp:HiddenField>
                        
                        </td>
                        <td>
                            Grupo
                        <asp:dropdownlist id="lstgrupo4" runat="server">
                            </asp:dropdownlist>
                        </td>
                        <!--
                        <td>
                            Valor
                            <asp:TextBox id="txtValor4" runat="server"></asp:TextBox>
                        </td>
                        -->
                    </tr>
                    <tr style="background-color:#CCFFFF" align="center" valign="middle">
                        <td class="style2">
                           <table><tr><td>Hora inicial: 
                            <asp:TextBox ID="inicial5Hora5" runat="server" maxlength="5" OnKeyUp="return(formatar(this, '##:##'));"></asp:TextBox></td><td>Hora final: 
                            <asp:TextBox ID="final5Hora5" runat="server" maxlength="5" OnKeyUp="return(formatar(this, '##:##'));"></asp:TextBox></td></tr></table> 
                            
                          
                        </td>
                        <td>
                            Disciplina
                        <asp:dropdownlist id="lstmateria5" runat="server">
                            </asp:dropdownlist>
                        </td>
                        <td>
                            Aluno
                            <asp:TextBox runat="server" id="txt5" class="aluno" ></asp:TextBox><asp:HiddenField id="hide5" runat="server" value="0"></asp:HiddenField>
                        
                        </td>
                        <td>
                            Grupo
                        <asp:dropdownlist id="lstgrupo5" runat="server">
                            </asp:dropdownlist>
                        </td>
                        
                        <!--
                        <td>
                            Valor
                            <asp:TextBox id="txtValor5" runat="server"></asp:TextBox>
							</td>
							</tr></table></td>
						-->
						
            
        </tr>
                    <tr style="background-color:#f6f9fc" align="center" valign="middle">
                        <td class="style2">
                         <table><tr><td>Hora inicial: 
                            <asp:TextBox ID="inicial6Hora6" runat="server" maxlength="5" OnKeyUp="return(formatar(this, '##:##'));"></asp:TextBox></td><td>Hora final: 
                            <asp:TextBox ID="final6Hora6" runat="server" maxlength="5" OnKeyUp="return(formatar(this, '##:##'));"></asp:TextBox></td></tr></table> 
                           
                        </td>
                        <td>
                            Disciplina
                        <asp:dropdownlist id="lstmateria6" runat="server">
                            </asp:dropdownlist>
                        </td>
                        <td>
                            Aluno
                            <asp:TextBox runat="server" id="txt6" class="aluno" ></asp:TextBox><asp:HiddenField id="hide6" runat="server" value="0"></asp:HiddenField>
                        
                        </td>
                        <td>
                            Grupo
                        <asp:dropdownlist id="lstgrupo6" runat="server">
                            </asp:dropdownlist>
                        </td>
                        
                        <!--
                        <td>
                            Valor
                            <asp:TextBox id="txtValor6" runat="server"></asp:TextBox>
							</td>
							</tr></table></td>
						-->
						
            
        </tr>
                    <tr style="background-color:#CCFFFF" align="center" valign="middle">
                        <td class="style5">
                          <table><tr><td>Hora inicial: 
                          
                            <asp:TextBox ID="inicial7Hora7" runat="server" maxlength="5" OnKeyUp="return(formatar(this, '##:##'));"></asp:TextBox></td><td>Hora final: 
                            <asp:TextBox ID="final7Hora7" runat="server" maxlength="5" OnKeyUp="return(formatar(this, '##:##'));"></asp:TextBox></td></tr></table> 
                            
                       
                        </td>
                        <td class="style6">
                            Disciplina
                        <asp:dropdownlist id="lstmateria7" runat="server">
                            </asp:dropdownlist>
                        </td>
                        <td class="style6">
                            Aluno
                            <asp:TextBox runat="server" id="txt7" class="aluno" ></asp:TextBox><asp:HiddenField id="hide7" runat="server" value="0"></asp:HiddenField>
                        
                        </td>
                        <td class="style6">
                            Grupo
                        <asp:dropdownlist id="lstgrupo7" runat="server">
                            </asp:dropdownlist>
                        </td>
                        
                        <!--
                        <td>
                            Valor
                            <asp:TextBox id="txtValor7" runat="server"></asp:TextBox>
							</td>
							</tr></table></td>
						-->
						
            
        </tr>
                    <tr style="background-color:#f6f9fc" align="center" valign="middle">
                        <td class="style2">
                         <table><tr><td>Hora inicial: 
                            <asp:TextBox ID="inicial8Hora8" runat="server" maxlength="5" OnKeyUp="return(formatar(this, '##:##'));"></asp:TextBox></td><td>Hora final: 
                            <asp:TextBox ID="final8Hora8" runat="server" maxlength="5" OnKeyUp="return(formatar(this, '##:##'));"></asp:TextBox></td></tr></table> 
                            
                            
                        </td>
                        <td>
                            Disciplina
                        <asp:dropdownlist id="lstmateria8" runat="server">
                            </asp:dropdownlist>
                        </td>
                        <td>
                            Aluno
                            <asp:TextBox runat="server" id="txt8" class="aluno" ></asp:TextBox><asp:HiddenField id="hide8" runat="server" value="0"></asp:HiddenField>
                        
                        </td>
                        <td>
                            Grupo
                        <asp:dropdownlist id="lstgrupo8" runat="server">
                            </asp:dropdownlist>
                        </td>
                        
                        <!--
                        <td>
                            Valor
                            <asp:TextBox id="txtValor8" runat="server"></asp:TextBox>
							</td>
							</tr></table></td>
						-->
						
            
        </tr>
    </table>
    
    <asp:panel id="Panel2" runat="server" ></asp:panel>
    </asp:panel>
</form>
</form>
<%--INICIO DA FUNÇÃO DO AUTOCOMPLETE--%>
<%

    System.Data.SqlClient.SqlConnection sqlc = new System.Data.SqlClient.SqlConnection(ConfigurationManager.AppSettings["baseDados"]);
    sqlc.Open();

    string select = "select * from aluno order by nomeAluno";

    System.Data.SqlClient.SqlCommand cmd = new System.Data.SqlClient.SqlCommand(select, sqlc);
    System.Data.SqlClient.SqlDataReader dr = cmd.ExecuteReader();

    System.Collections.Generic.List<string> alunos = new System.Collections.Generic.List<string>();
    System.Collections.Generic.List<string> codigoAlunos = new System.Collections.Generic.List<string>();
    System.Collections.Generic.List<string> statuss = new System.Collections.Generic.List<string>();

    if (dr.HasRows)
    {
        while (dr.Read())
        {
            //alunos.Add("\"" + dr["nomeAluno"].ToString() + "\",");
            alunos.Add(dr["nomeAluno"].ToString());
            codigoAlunos.Add("\"" + dr["codigoAluno"].ToString() + "\",");
            statuss.Add("\"" + statusVer(dr["codigoAluno"].ToString()) + "\",");
        }
    }

    dr.Close();

    sqlc.Close();

    string aluno = "";
    int cont = 0;
    foreach (var item in alunos)
    {
        if (statuss[cont] == "\"sim\",")
        {
            aluno += "\"" + item + " - Inadimplente\",";
        }
        else
        {
            aluno += "\"" + item + "\",";
        }
        cont++;
    }
    int tamanho = aluno.Length;
    aluno = aluno.Substring(0, tamanho - 1);

    string codigoAluno = "";
    foreach (var item in codigoAlunos)
    {
        codigoAluno += item;
    }
    tamanho = codigoAluno.Length;
    codigoAluno = codigoAluno.Substring(0, tamanho - 1);

    string status = "";
    foreach (var item in statuss)
    {
        status += item;
    }
    tamanho = status.Length;
    status = status.Substring(0, tamanho - 1);

    //ALUNO E codigoALUNO sao strings que possuem na mesma ordem os códigos e nomes dos alunos separados por virgula

%>

<script type="text/javascript">
    
        //esta funcao deveria saber a hora
        function findValue(li) {
            if (li == null) return alert("Não encontrado!");

            // if coming from an AJAX call, let's use the CityId as the value
            if (!!li.extra) var sValue = li.extra[0];

            // otherwise, let's just display the value in the text box
            else var sValue = li.selectValue;
            
            // criados 2 arrays recenbendo as informações do nome do aluno e o codigo
            
            //aqui fazemos com que a variavel .net seja escrita dentro do array java script
            
            var nomeAluno = new Array(<%Response.Write(aluno);%>);
            var codigoAluno = new Array(<%Response.Write(codigoAluno);%>);
            var status = new Array(<%Response.Write(status);%>);
            
            // variáveis p/verificar as posições relacionado com o codigo
            var posicao = nomeAluno.indexOf(li.selectValue);
            var codigo = codigoAluno[posicao];
            var statusInadimplencia = status[posicao];
            
            // mensagem com o valor de codigo
            //alert("O aluno(a) selecionado foi: " + codigo);
            
            //if(statusInadimplencia == "sim") return alert("O aluno(a) selecionado foi: " + codigo + ", "+ nomeAluno+", "+ status +"");
            
            //a_codigoProfessor_dia_hid_hhmm
            
            var codigoProfessor = document.getElementById('lstProfessor').value;     
            var codigoDia = document.getElementById('lstDia').value;  
            
            //aqui neste momento, agora que li ja possui um valor de id igual ao nome 
            //do txt (deveremos fazer replace em txt por hid de hidden)
            
            var nomeHidden = li.id.replace("txt","hide"); 
            
            var objHid = document.getElementById(nomeHidden);           
                       
            objHid.value = codigo;
        }

        function selectItem(li) {
            findValue(li);
        }

        function formatItem(row) {
            return row[0] + " (id: " + row[1] + ")";
        }

        $(document).ready(function() {
        
            $(".aluno").autocompleteArray(
		    [
		    <%Response.Write(aluno);%>            
		    ], 
		    [
		    <%Response.Write(codigoAluno);%>            
		    ], 
		{
		    delay: 10,
		    minChars: 1,
		    matchSubset: 1,
		    onItemSelect: selectItem,
		    onFindValue: findValue,
		    autoFill: true,
		    maxItemsToShow: 10
		}
        
	);
        });
</script>


<%--FIM DA FUNÇÃO DO AUTOCOMPLETE--%>